
import { Button, Flex, Form } from "@/components/base";
import { useNavigate } from "react-router-dom";
import * as UI from "../../ui";
import * as hooks from "./hooks";
import * as apis from "@/apis";
import React from "react";

/** 订单审核 */
export function OrderApproval() {

    const navigate = useNavigate();
    const [form] = Form.useForm();
    const { id } = hooks.useSearchId();
    hooks.useOrderDetails(id, form);

    const reject = React.useCallback(async () => {
        await apis.order.update.post({id, orderStatus: apis.order.OrderStatus.待下单 });
        navigate(-1);
    }, [id, navigate]);

    const passThrough = React.useCallback(async () => {
        await apis.order.update.post({id, orderStatus: apis.order.OrderStatus.待安排 });
        navigate(-1);
    } , [id, navigate]);

    return (
        <Form form={form} layout='vertical' >
            <Flex justify='flex-end' gap={10} align='center' style={{ marginBottom: 20 }} >
                <Button onClick={() => { navigate(-1) }} >返回</Button>
                <Button onClick={reject}  >驳回</Button>
                <Button onClick={passThrough} type='primary' >通过</Button>
            </Flex>
            <UI.FormItem readOnly />
        </Form>
    )
}
